<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
class LoginController extends \App\Http\Controllers\AdminController {
    public function index(Request $request) {
        if ($request->ajax()) {
            $users = \Illuminate\Support\Facades\Config::get("adminuser.users.{$request->input('name')}");
            if (!$users) {
                return [
                    'status'    => 0,
                    'info'      => "帐号不存在"
                ];
            }
            if ($users != trim($request->input('password'))) {
                return [
                    'status'    => 0,
                    'info'      => "密码错误"
                ];
            }
            Session::put('admin', ['name' => trim($request->input('name')), 'time' => time()]);
            Session::save();
            return [
                'status'        => 1,
                'info'          => '登录成功'
            ];
        }
        return view('admin.login.index');
    }
    /**
     * 执行用户登录操作
     * @param Request $request
     */
    public function logout(Request $request) {
        Session::forget('admin');
        return redirect('admin/login/index');
    }
}
